package datas
{
	import flash.filesystem.File;
	
	import main.DataSubBase;
	
	import message.UpdateVersionSource;
	import message.UpdateVersionSourceReturn;
	
	public class UpdateData extends DataSubBase
	{
		private var file:File;
		
		public function UpdateData()
		{
		}
		
		public function getUpdateList(versionID:uint):void
		{
			this.registerMessageHandler(UpdateVersionSourceReturn.CMD,backHandler);
			
			var msg:UpdateVersionSource = new UpdateVersionSource;
			msg.versionId = versionID;
			
			this.send(msg);
		}
		
		private function backHandler(value:UpdateVersionSourceReturn):void
		{
			var list:Array = value.records;
			if(list){
				for(var i:int = 0;i < list.length;i++){
					deleteThisFile(list[i].updateSourcePath);
				}
			}
		}
		
		private function deleteThisFile(str:String):void
		{
			var path:String = str.split("assets/")[1];
			
			file = File.documentsDirectory.resolvePath("iWeiHai/" + path);
			if(file.exists){
				file.deleteFile();
			}
		}
		
	}
}